"""
@File  :__init__.py.py
@Author:王世锋
@Date  :2023/7/1515:30
@Desc  :
"""
import hashlib
import json

def create_sign(pay_data, mch_key):
    """
    签名加密
    :param mch_key:
    :param pay_data:
    :return:
    """
    with open("log.txt", "w") as f:
        f.write(pay_data)
        f.write(mch_key)
    from urllib.parse import urlencode
    npay_data = {}
    pay_data = json.loads(pay_data)
    for k in sorted(pay_data):
        npay_data[k] = pay_data[k]
    params = urlencode(npay_data)
    # print(params)
    stringSignTemp = "{}{}".format(params, mch_key)
    # print("stringSignTemp==", stringSignTemp)
    sign = hashlib.sha512(stringSignTemp.encode('utf-8')).hexdigest()
    return sign

if __name__ == '__main__':
    import sys
    argv = sys.argv[1:]
    a = create_sign(argv[0], argv[1])
    print(a)